All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class quicktime.app.time.TaskThread

java.lang.Object
   |
   +----quicktime.app.time.TaskThread

public class TaskThread
extends Object
implements Runnable, Collection
The TaskThread class maintains a table of Taskable objects that will periodically have their task method called. Each time an instance of this class is created a new thread is spawned when the start method of the TaskThread object is called. The thread is stopped when the stop method is called. Taskable objects can be added or removed from TaskThreads at the applications discretion.

When the thread is running it calls its Taskable member's task method. When it has completed a single iteration of its members it will sleep for the specified sleepTime and then go through the process again until the thread is stopped.

A TaskThread object must be explicitly started - just adding a Taskable object to the collection is not sufficient to start the thread. However, once all of the Taskable objects are removed from the collection the thread will stop. To ensure that adding a Taskable object to a TaskThread will also have the thread started the addAndStart method can be used.

If a member's task() method throws an Exception it is uncerimoniously removed from the TaskThread collection - no notification is given of such an occurance.


Constructor Index

 o TaskThread(String)
Creates a TaskThread object.
 o TaskThread(String, int)
Creates a TaskThread object.

Method Index

 o addAndStart(Taskable)
This method will add a taskable client to the list.
 o addMember(Object)
This method will add a taskable client to the list.
 o finalize()
 o getPriority()
Returns the current priority of the task thread.
 o getSleepTime()
The time that the thread will sleep.
 o hasMember(Object)
Return true if the Taskable object is currently a member of the task list.
 o isAlive()
Returns the alive state of the thread.
 o isAppropriate(Object)
Returns true if the object is an instance of the Taskable interface.
 o isEmpty()
Returns true if there are no Taskable objects in the collection
 o killAllThreads()
 o members()
Returns an Enumeration for the current Taskable members of the collection.
 o removeAll()
Remove all task objects from the task list and stops the task thread.
 o removeMember(Object)
Removes the Taskable object from the collection.
 o resume()
Resumes the execution of the task thread.
 o run()
Calls task on each of the task object in the internal task list.
 o setPriority(int)
Sets the priority of the thread.
 o setSleepTime(int)
The sleepTime for the thread.
 o size()
Return the number of task current objects.
 o start()
This will create a thread and start it running, calling task on each of the items you have added to the TaskThread object.
 o stop()
This will destroy the thread and end the periodic calling of task objects.
 o suspend()
Suspends the execution of the task thread.
 o toString()
String representation of the class.

Constructors

 o TaskThread
 public TaskThread(String tName)
Creates a TaskThread object. When the object's start method is called the supplied name will be the name of the thread that is created by the task thread object. The default sleep time for a TaskThread's thread is 10msecs.

Parameters:
tName - the name of the thread
 o TaskThread
 public TaskThread(String tName,
                   int sleepTime)
Creates a TaskThread object. When the object's start method is called the supplied name will be the name of the thread that is created by the task thread object.

Parameters:
sleepTime - sets the sleep time that will be used when the thread starts

Methods

 o killAllThreads
 public static final void killAllThreads()
 o getSleepTime
 public int getSleepTime()
The time that the thread will sleep.

 o setSleepTime
 public void setSleepTime(int newTime)
The sleepTime for the thread. If the sleepTime is set to zero, the thread will only yield (but not sleep), otherwise it sleeps for the given time.

 o addMember
 public boolean addMember(Object member)
This method will add a taskable client to the list. It will not alter the state of the thread.

Parameters:
t - a taskable client that wants to be called periodically
 o isAppropriate
 public boolean isAppropriate(Object object)
Returns true if the object is an instance of the Taskable interface.

Returns:
a boolean
 o members
 public Enumeration members()
Returns an Enumeration for the current Taskable members of the collection.

Returns:
an Enumeration
 o addAndStart
 public void addAndStart(Taskable t)
This method will add a taskable client to the list. If the thread was stopped (because there were no objects to task) this will start the thread up.

Parameters:
t - the Taskable object to add to the collection.
 o removeMember
 public void removeMember(Object member)
Removes the Taskable object from the collection. If this would leave the collection empty then the internal thread is stopped.

Parameters:
t - a task client that wants to be called periodically
 o removeAll
 public void removeAll()
Remove all task objects from the task list and stops the task thread.

 o size
 public int size()
Return the number of task current objects.

Returns:
an int
 o hasMember
 public boolean hasMember(Object object)
Return true if the Taskable object is currently a member of the task list.

Parameters:
object - the object to test if a member
Returns:
true if the object is a member
 o isEmpty
 public boolean isEmpty()
Returns true if there are no Taskable objects in the collection

Returns:
a boolean
 o start
 public void start()
This will create a thread and start it running, calling task on each of the items you have added to the TaskThread object. If a thread is already active this call has no effect

 o stop
 public void stop()
This will destroy the thread and end the periodic calling of task objects. You can restart this object later by calling start. The priority and sleepTime will be persistent across start and stop calls, as will the task objects themselves.

 o suspend
 public void suspend()
Suspends the execution of the task thread.

 o resume
 public void resume()
Resumes the execution of the task thread.

 o isAlive
 public boolean isAlive()
Returns the alive state of the thread.

 o getPriority
 public int getPriority()
Returns the current priority of the task thread.

Returns:
the task thread priority or PRIORITY_NOT_SET if the TaskThread object has not had a priority explicitly set.
 o setPriority
 public void setPriority(int newPriority)
Sets the priority of the thread.

Parameters:
newPriority - the new priority of the thread or any consequent threads created.
 o run
 public void run()
Calls task on each of the task object in the internal task list. If an object's task call fails it is removed from the collection.

 o finalize
 protected void finalize() throws Throwable
Overrides:
finalize in class Object
 o toString
 public String toString()
String representation of the class.

Overrides:
toString in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index